/**************************************************************/
/*  This file is licensed from, and is a trade secret of:     */
/*                                                            */
/*    Mercury Computer Systems, Incorporated                  */
/*    199 Riverneck Road                                      */
/*    Chelmsford, Massachusetts 01824-2820                    */
/*    United States of America                                */
/*    Telephone + 1 978 256-1300                              */
/*                                                            */
/*  Refer to your Software License Agreement for provisions   */
/*  on use, duplication, or disclosure.                       */
/*  US. Government users and prime contractors are also       */
/*  governed by the following Data Rights Notice:             */
/*  Use, duplication or disclosure by the US. Government is   */
/*  subject to the provisions set forth in FAR 52.227-14 for  */
/*  restricted rights or other agency data rights provisions  */
/*  on commercial software and documentation, as applicable.  */
/*                                                            */
/*  This file: (a) was developed at private expense, and no   */
/*  part was developed with government funds, (b) is a        */
/*  trade secret of Mercury Computer Systems, Inc. for the    */
/*  purposes of the Freedom of Information Act, (c) is        */
/*  "commercial computer software" subject to limited         */
/*  utilization as provided in the above noted Software       */
/*  License Agreement and (d) is in all respects data         */
/*  belonging exclusively to Mercury Computer Systems, Inc..  */
/*                                                            */
/**************************************************************/

/******************************************************************/
/* Copyright (c) 1999-2003, Mercury Computer Systems, Inc.,       */
/* Chelmsford MA.,and all third party embedded software sources.  */
/* All rights reserved under the Copyright laws of US. and        */
/* international treaties.                                        */
/*                                                                */
/* Patent Pending                                                 */
/******************************************************************/


//$COPYRIGHT_END


#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <assert.h>
#include "FileIO.h"

enum IODataType
ConvertStringToDataTypeEnum (const char *data_type_string)
{
  enum IODataType data_type;

  if (strcmp(data_type_string, DT_OCTET_TYPE_STR) == 0) {
    data_type = FILE_IO_DT_OCTET;
  }
  else if (strcmp(data_type_string, DT_CHAR_TYPE_STR) == 0) {
    data_type =  FILE_IO_DT_CHAR;
  }
  else if (strcmp(data_type_string, DT_SHORT_TYPE_STR) == 0) {
    data_type =  FILE_IO_DT_SHORT;
  }
  else if (strcmp(data_type_string, DT_USHORT_TYPE_STR) == 0) {
    data_type =  FILE_IO_DT_USHORT;
  }
  else if (strcmp(data_type_string, DT_LONG_TYPE_STR) == 0) {
    data_type =  FILE_IO_DT_LONG;
  }
  else if (strcmp(data_type_string, DT_ULONG_TYPE_STR) == 0) {
    data_type =  FILE_IO_DT_ULONG;
  }
  else if (strcmp(data_type_string, DT_FLOAT_TYPE_STR) == 0) {
    data_type =  FILE_IO_DT_FLOAT;
  }
  else if (strcmp(data_type_string, DT_DOUBLE_TYPE_STR) == 0) {
    data_type =  FILE_IO_DT_DOUBLE;
  }
  else {
    throw "Encountered unexpected data type";
  }
  return data_type;
} // End of ConvertStringToDataTypeEnum()

size_t
GetSizeOfDataType (enum IODataType data_type)
{
  size_t data_size;

  switch (data_type) {
  case FILE_IO_DT_OCTET:
    data_size = sizeof(char);  
    break;
  case FILE_IO_DT_CHAR:
    data_size = sizeof(char);  
    break;
  case FILE_IO_DT_SHORT:
    data_size = sizeof(short);  
    break;
  case FILE_IO_DT_USHORT:
    data_size = sizeof(unsigned short);  
    break;
  case FILE_IO_DT_LONG:
    data_size = sizeof(long);  
    break;
  case FILE_IO_DT_ULONG:
    data_size = sizeof(unsigned long);  
    break;
  case FILE_IO_DT_FLOAT:
    data_size = sizeof(float);  
    break;
  case FILE_IO_DT_DOUBLE:
    data_size = sizeof(double);  
    break;
  default:
    throw "Encountered unexpected data type";
  }
  return data_size;
} // End of GetSizeOfDataType()
